package com.assessment.service.impl;

import com.assessment.entity.*;
import com.assessment.mapper.*;
import com.assessment.service.AdepService;
import com.assessment.service.AroleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.management.relation.Role;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 鑫十一
 * @since 2021-12-15
 */
@Service
@Transactional
public class AroleServiceImpl extends ServiceImpl<AroleMapper, Arole> implements AroleService {

    @Autowired(required = false)
    private AdepMapper adepMapper;
    @Autowired(required = false)
    private ApeoMapper apeoMapper;
    @Autowired(required = false)
    private AitemavgMapper aitemavgMapper;
    @Autowired(required = false)
    private AscoreMapper ascoreMapper;

    @Override
    public List<Column> getColumns() {
        List<Column> columns = new ArrayList<>();
        columns.add(new Column().setLabel("角色名").setProp("name"));
        columns.add(new Column().setLabel("角色类型").setProp("type"));
        columns.add(new Column().setLabel("角色位次").setProp("rsit"));
        return columns;
    }

    @Override
    public boolean updateRole(Arole item) {
        // 更新部门
        Adep adep = new Adep();
        adep.setRsit(item.getRsit());
        adep.setRtype(item.getType());
        adep.setRname(item.getName());
        adepMapper.update(adep,new QueryWrapper<Adep>().eq("rid",item.getId()));

        Apeo apeo = new Apeo();
        apeo.setRsit(item.getRsit());
        apeo.setRtype(item.getType());
        apeo.setRname(item.getName());
        apeoMapper.update(apeo,new QueryWrapper<Apeo>().eq("rid",item.getId()));
        Apeo apeo1 = new Apeo();
        apeo1.setDsit(item.getRsit());
        apeo1.setDrole(item.getName());
        apeoMapper.update(apeo1,new QueryWrapper<Apeo>().eq("drid",item.getId()));

        Aitemavg aitemavg = new Aitemavg().setPrtype(item.getType()).setPsit(item.getRsit()).setProle(item.getName());
        aitemavgMapper.update(aitemavg,new QueryWrapper<Aitemavg>().eq("prid",item.getId()));

        Ascore ascore = new Ascore().setBrtype(item.getType()).setBrole(item.getName()).setBrsit(item.getRsit());
        ascoreMapper.update(ascore,new QueryWrapper<Ascore>().eq("brid",item.getId()));

        Ascore ascore1 = new Ascore().setArtype(item.getType()).setArole(item.getName());
        ascoreMapper.update(ascore1,new QueryWrapper<Ascore>().eq("arid",item.getId()));

        this.updateById(item);

        return true;
    }
}
